using Microsoft.EntityFrameworkCore;
namespace ShopForWeb.Models;
public class ShopDbContext : DbContext
{
  public ShopDbContext(DbContextOptions options) : base(options)
  {
  }

  protected override void OnModelCreating(ModelBuilder modelBuilder)
  {
    //Annkotion 标注 --> FluentAi modelBuilder

    //复合主键
    modelBuilder.Entity<OrderDetails>()
                  .HasKey(o => new { o.CommodityID, o.OrderID });
    modelBuilder.Entity<ShopCart>()
                  .HasKey(o => new { o.CommodityID, o.UserID });

    //种子数据
    modelBuilder.Entity<User>().HasData(
        new User
        {
          UserID = 1,
          Name = "默认用户",
          Password = "123456",
          Phone = "18655667788",
          Sex = "男",
          Nick = "默认用户"
        }
      );
    modelBuilder.Entity<Manager>().HasData(
     new Manager
     {
       ManagerID = 1,
       Password = "123456",
       Phone = "13201020304",
       Name = "系统管理员",
       Sex = "男"
     }
   );
  }

  public DbSet<User> Users { get; set; } = null!;
  public DbSet<Order> Orders { get; set; } = null!;
  public DbSet<Manager> Managers { get; set; } = null!;
  public DbSet<Commodity> Commoditys { get; set; } = null!;
  public DbSet<ShopCart> ShopCarts { get; set; } = null!;

  public DbSet<OrderDetails> OrderDetails { get; set; } = null!;


}
